import { httpClient } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { ModuleOutputDto } from './model';
import { FunctionOutputDtoSimple } from '@/api/authorization/admin/function/model';
import { PageRequest, PageData } from '@/utils/common/types';

/** 管理-模块信息枚举 */
enum Api {
  /** 读取模块信息 */
  Read = '/api/admin/module/read',
  /** 读取模块[用户]树数据 */
  ReadUserModules = '/api/admin/module/readUserModules',
  /** 读取模块[角色]树数据 */
  ReadRoleModules = '/api/admin/module/readRoleModules',
  /** 读取模块功能 */
  ReadFunctions = '/api/admin/module/readFunctions',
}

//#region 读取模块信息
/**
 * 读取模块信息
 * @param mode 错误消息模型
 */
export function readModules(mode: ErrorMessageMode = 'message') {
  return httpClient.post<ModuleOutputDto[]>(
    {
      url: Api.Read,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 读取模块[用户]树数据
/**
 * 读取模块[用户]树数据
 * @param userId 用户编号
 * @param mode 错误消息模型
 */
export function readUserModules(userId: string | bigint, mode: ErrorMessageMode = 'message') {
  return httpClient.get<any[]>(
    {
      url: Api.ReadUserModules,
      params: { userId: userId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 读取模块[角色]树数据
/**
 * 读取模块[角色]树数据
 * @param roleId 角色编号
 * @param mode 错误消息模型
 */
export function readRoleModules(roleId: string | bigint, mode: ErrorMessageMode = 'message') {
  return httpClient.get<any[]>(
    {
      url: Api.ReadRoleModules,
      params: { roleId: roleId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 读取模块功能
/**
 * 读取模块功能
 * @param request 分页请求
 * @param mode 错误消息模型
 */
export function readModuleFunctions(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<FunctionOutputDtoSimple>>(
    {
      url: Api.ReadFunctions,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
